home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Adobe Air 1.5 / AdobeAIRInstaller.exe / Adobe AIR / Versions / 1.0 / Adobe AIR Application Installer.swf / scripts / components / ExtendedImage.as next >
Encoding:
Text File  |  2008-10-29  |  2.4 KB  |  89 lines

  1. package components
  2. {
  3.    import flash.events.SecurityErrorEvent;
  4.    import flash.filesystem.File;
  5.    import flash.filesystem.FileMode;
  6.    import flash.filesystem.FileStream;
  7.    import flash.utils.ByteArray;
  8.    import mx.controls.Image;
  9.    import mx.events.PropertyChangeEvent;
  10.    
  11.    public class ExtendedImage extends Image
  12.    {
  13.       private var _sourceFilePath:String;
  14.       
  15.       public function ExtendedImage()
  16.       {
  17.          super();
  18.          this.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onSecurityError);
  19.       }
  20.       
  21.       override protected function commitProperties() : void
  22.       {
  23.          var fs:FileStream = null;
  24.          var f:File = null;
  25.          var bytes:ByteArray = null;
  26.          if(this._sourceFilePath)
  27.          {
  28.             try
  29.             {
  30.                f = new File(this._sourceFilePath);
  31.                fs = new FileStream();
  32.                fs.open(f,FileMode.READ);
  33.                bytes = new ByteArray();
  34.                fs.readBytes(bytes,0,fs.bytesAvailable);
  35.                source = bytes;
  36.             }
  37.             catch(e:Error)
  38.             {
  39.                source = getStyle("brokenImageSkin");
  40.             }
  41.             finally
  42.             {
  43.                if(fs)
  44.                {
  45.                   fs.close();
  46.                }
  47.             }
  48.          }
  49.          super.commitProperties();
  50.       }
  51.       
  52.       [Bindable(event="propertyChange")]
  53.       public function set sourceFilePath(param1:String) : void
  54.       {
  55.          var _loc2_:Object = this.sourceFilePath;
  56.          if(_loc2_ !== param1)
  57.          {
  58.             this._2099171076sourceFilePath = param1;
  59.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"sourceFilePath",_loc2_,param1));
  60.          }
  61.       }
  62.       
  63.       private function onSecurityError(param1:SecurityErrorEvent) : void
  64.       {
  65.          trace("SecurityError: " + param1.errorID + " : ");
  66.       }
  67.       
  68.       private function set _2099171076sourceFilePath(param1:String) : void
  69.       {
  70.          if(param1 == null && Boolean(this._sourceFilePath))
  71.          {
  72.             source = null;
  73.             this._sourceFilePath = null;
  74.          }
  75.          else
  76.          {
  77.             this._sourceFilePath = param1;
  78.          }
  79.          invalidateProperties();
  80.       }
  81.       
  82.       public function get sourceFilePath() : String
  83.       {
  84.          return this._sourceFilePath;
  85.       }
  86.    }
  87. }
  88.  
  89.